package fr.tvbarthel.games.chasewhisply.ui.gameviews;

import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;

import com.tcl.VincentLuRebound.SimpleSpringListener;
import com.tcl.VincentLuRebound.Spring;
import com.tcl.VincentLuRebound.SpringUtil;

import fr.tvbarthel.games.chasewhisply.GameActivity;
import fr.tvbarthel.games.chasewhisply.mechanics.behaviors.GameBehavior;
import fr.tvbarthel.games.chasewhisply.model.TargetableItem;
import fr.tvbarthel.games.chasewhisply.ui.AnimationLayer;

import static fr.tvbarthel.games.chasewhisply.model.DisplayableItemFactory.TYPE_BLOND_GHOST;
import static fr.tvbarthel.games.chasewhisply.model.DisplayableItemFactory.TYPE_EASY_GHOST;


/**
 * Created by vigou on 2017/11/3.
 */

public class CanimateOfGhost extends SimpleSpringListener
{
    private final String TAG = CanimateOfGhost.class.getName() ;

    private TargetableItem mItem ;

    private Bitmap mHandBitmap;

    private AnimationLayer mAnimationLayerHand ;

    private   Context mContext ;

    private static  boolean mshow ;

    private GameBehavior.IGameBehavior mGameBehavior =null;

    public CanimateOfGhost(TargetableItem item , Context context)
    {
        mItem = item ;

        mContext = context ;

        mshow = false;

        mAnimationLayerHand = ((GameActivity)context).getHandLayer() ;
    }

//    public CanimateOfGhost(TargetableItem item , Context context, GameBehavior.IGameBehavior gameBehavior)
//    {
//        this(item,context);
//        mGameBehavior = gameBehavior;
//    }

    @Override
    public void onSpringUpdate(Spring spring)
    {

        super.onSpringUpdate(spring);

        Log.d(TAG, " onSpringUpdate currentValue == " + spring.getCurrentValue() + "Velocity:" + spring.getVelocity());

        float mappedValue = (float) SpringUtil.mapValueFromRangeToRange(spring.getCurrentValue(), 0, 1, 1, 2);

        Log.i(TAG,"DisplayableItem Z before =" + mItem.getZ() );
        Log.i(TAG,"mappedValue =" + mappedValue );
        mItem.setZ(mappedValue);

        double value = spring.getCurrentValue() ;

        Log.i(TAG,"spring.getEndValue() =" +spring.getEndValue() );
       if ( !mshow && spring.getEndValue() -value < 1)
        {
            double temp = spring.getEndValue() -value ;
            Log.i(TAG,"spring.getEndValue() -value=" + temp );
            ShowHand();
            Log.i(TAG,"show hand =" );
            mshow = true ;
        }

    }

    public void  ShowHand()
    {
        mAnimationLayerHand.drawDyingGhost(null,1,200,50,50);

//        mAnimationLayerHand.postDelayed(new Runnable() {
//            @Override
//            public void run() {
//                ((GameActivity)mContext).onGameEngineStop();
//            }
//        },1000);

    }
}

